#!/bin/bash

function die {
   [ $1 -ne 0 ] && echo -e "\n\e[31m✘ Error!\e[0m Pre-commit hook failed. Nothing commited."

   git stash pop -q stash@{$STASH_NAME}

   exit $1
}

STASH_NAME="pre-commit-$(date +%s)"
git stash save -q --keep-index $STASH_NAME

./vendor/bin/phpunit -c phpunit.xml || die $?
./vendor/bin/phpunit -c phpunit.integration.xml || die $?
./vendor/bin/php-cs-fixer fix --dry-run || die $?

die 0
